from sqlmodel import SQLModel
from sqlmodel import create_engine,Session
db_url = "sqlite:///001_many_to_many.db"
engine = create_engine(db_url, echo=True,connect_args={"check_same_thread":False})
def get_db(): 
    return Session(engine,expire_on_commit=False)
def close_db():
    if engine:
        engine.dispose()

def init_db(is_drop:bool=False,is_created:bool=True):
    if is_drop:
        SQLModel.metadata.drop_all(engine)
    if is_created:
        SQLModel.metadata.create_all(engine)
    print("数据库初始化完成")